<?php
App::uses('AppController', 'Controller');

class ServicesController extends AppController 
{
	public $components = array('Paginator');
	public $uses = array('Services','Category','Zone');

	private $option_time=array(
	//'5'=>'05',
	'10'=>'10 min',
	'15'=>'15 min',
	'20'=>'20 min',
	'25'=>'25 min',
	'30'=>'30 min',
	'35'=>'30 min',
	'40'=>'40 min',
	'45'=>'45 min',
	'50'=>'50 min',
	'55'=>'55 min',
	'60'=>'1 hs',
	'65'=>'1:05 hs',
	'70'=>'1:10 hs',
	'75'=>'1:15 hs',
	'80'=>'1:20 hs',
	'85'=>'1:25 hs',
	'90'=>'1:30 hs',
	'95'=>'1:35 hs',
	'100'=>'1:40 hs',
	'105'=>'1:45 hs',
	'110'=>'1:50 hs',
	'115'=>'1:55 hs',
	'120'=>'2 hs',
	//'105'=>'1:45 hs',
	);
//var_dump($option_time);
	public function index() {
		$this->set("title_for_layout",'Servicios');	
		$pagination_settings= array();
		if(isset($this->data['keyword'])){
			$keyword = $this->data['keyword'];
			$pagination_settings['conditions']= array('Services.name LIKE' => "$keyword%");			
			//$pagination_settings['OR']= array('Category.name LIKE' => "$keyword%",'Zone.name LIKE' => "$keyword%");	
		}
		$pagination_settings['limit'] =30;
		$this->Paginator->settings =$pagination_settings;

		
	    $services = $this->Paginator->paginate('Services');
		$categories = $this->Category->find('all');
		//var_dump($categories);
		$this->set('data',$services);			
	}

	public function add(){
		$this->set("title_for_layout",'Nuevo Servicio');
		if (!empty($this->data))
		{		
			//var_dump($this->data);
			$this->Services->set($this->data);
			if($this->Services->validates()){
				if($this->Services->save($this->data)){
					$this->redirect('/services');
				}
				else{
					$errors = $this->Services->invalidFields();
					$this->Session->setFlash(__($errors, true), 'flash', array('class' => 'alert alert-error'));
				}
			}
			else{
				$errors = $this->Services->invalidFields();
				$this->Session->setFlash(__($errors, true), 'flash', array('class' => 'alert alert-error'));
			}	
		}	
		$categories = $this->Category->find('list');
		$zones = $this->Zone->find('list');
		//var_dump($categories);
		$this->set('categories',$categories);		
		$this->set('zones',$zones);	
		$this->set('time_options',$this->option_time);	
	}

	public function edit($id) {
		$this->set("title_for_layout",'Editar Servicio');	

        if (!empty($this->data)){
        	$this->Services->id = $id;
            if ($this->Services->save($this->data)) {
                $this->Session->setFlash('Servicio Actualizado.', 'flash', array('class' => 'thrill'));
                $this->redirect('/services');
            }
        }
        else {

            $this->request->data = $this->Services->findById($id);
        }
        $categories = $this->Category->find('list');
		$zones = $this->Zone->find('list');
		//var_dump($categories);
		$this->set('categories',$categories);		
		$this->set('zones',$zones);		
    }
}
